var page = 1;

function myready() {
	changeh(document.documentElement.scrollHeight+500);
	$(".game_class a.g" + gid).addClass("selected");
	$(".game_class a").click(function() {
		window.location.href = "cssz.php?xtype=times&gid=" + $(this).attr('gid')
	});
	$(".data_table td").mouseover(function() {
		$(this).parent().addClass("hover")
	}).mouseout(function() {
		$(this).parent().removeClass("hover")
	});
	$(".edittime").click(function() {
		var posi = $(this).position();
		$(".time").css("left", posi.left);
		$(".time").css("top", posi.top + $(this).height() + 10);
		$(".time").show()
	});
	$(".close").click(function() {
		$(".time").hide()
	});
	var pcount = Number($(".page_info").attr('pcount'));
	page = Number($(".page_info").attr('page'));
	var pstr = "<select>";
	for (i = 1; i <= pcount; i++) {
		if (i == page) {
			pstr += "<option value='" + i + "' selected>" + i + "</option>"
		} else {
			pstr += "<option value='" + i + "'>" + i + "</option>"
		}
	}
	pstr += "</select>";
	$(".page_control").html(pstr);
	pstr = null;
	$(".page select").change(function() {
		page = Number($(this).val());
		window.location.href = "cssz.php?xtype=times&gid=" + $(this).attr('gid') + "&page=" + page
	});
	$(".send").click(function() {
		var str = '{';
		var i = 0;
		var err = false;
		$(".times").each(function() {
			var oo = r0($(this).find(".o").val());
			var cc = r0($(this).find(".c").val());
			var gid = $(this).attr('gid');
			var io = 0;
			if ($(this).find("input:checkbox").prop("checked") == true) {
				io = 1
			}
			if (i > 0) str += ',';
			str += '"' + i + '":{"gid":"' + gid + '","o":"' + oo + '","c":"' + cc + '","io":"' + io + '"}';
			if (oo % 1 != 0) err = true;
			if (cc % 1 != 0) err = true;
			i++
		});
		str += '}';
		if (err) {
			alert("请输入整数！");
			return false
		}
		str = '&times=' + str + '&gid=' + gid;
		$.ajax({
			type: 'POST',
			url: 'cssz.php',
			data: 'xtype=settimes' + str,
			success: function(m) {
				if (Number(m) == 1) {
					alert("修改成功");
					window.location.href = window.location.href
				}
			}
		})
	})
}
function r0(v) {
	if (isNaN(v) | v == '') {
		return 0
	}
	return v
}